import XtxConfirm from './xtx-confirm.vue'
import { createApp } from 'vue'
export default function (obj) {
  return new Promise((resolve, reject) => {
    // 1：读取组件内容
    const app = createApp(XtxConfirm, { ...obj, resolveFn, rejectFn })
    // 将该组件渲染到一个dom上
    const div = document.createElement('div')
    document.body.appendChild(div)
    app.mount(div)
    // 点击确定执行resolve() 点击取消执行 reject()
    function resolveFn () {
      remove()
      resolve()
    }
    function rejectFn () {
      remove()
      reject()
    }
    // 销毁
    function remove () {
      app.unmount(div)
      document.body.removeChild(div)
    }
    // resolve():点击了确定后调用
    // reject()：点击了取消后调用
  })
}
